package com.lzp.badminton.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzp.badminton.config.ResultMessage;
import com.lzp.badminton.service.IActivityService;
import com.lzp.badminton.vo.ActivityClubJoin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {
    @Autowired
    private ResultMessage resultMessage;
    @Autowired
    private IActivityService iActivityService;

    /**
     * 获取参与活动的数据
     * */
    @GetMapping(value = "/getActivityInfo")
    @ResponseBody
    public ResultMessage getActivityInfo(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        Page<ActivityClubJoin> iPage = iActivityService.getActivityInfo(new Page<ActivityClubJoin>(pageNum, pageSize));

        if (iPage.getRecords().size() != 0) {
            Map result = new HashMap();
            result.put("activityinfo", iPage);
            resultMessage.success("200", "获取成功", result);
            return resultMessage;
        } else {
            resultMessage.fail("404", "没有更多数据");
            return resultMessage;
        }
    }

    /**
     * 根据id获取参与活动的数据
     * */
    @GetMapping(value = "/getActivityInfoById")
    @ResponseBody
    public ResultMessage getActivityInfoById(@RequestParam("activityId") int activityId) {

        ActivityClubJoin acj = iActivityService.getActivityInfoById(activityId);

        resultMessage.success("200", "获取成功", acj);
        return resultMessage;

    }
}
